<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author XPF
-->
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #tableTitle>
        <Icon :icon="getTitle.icon" class="m-1 pr-1" />
        <span> {{ getTitle.value }} </span>
      </template>
      <template #toolbar>
        <a-button type="primary" @click="handleForm({})" v-auth="'sports:sportsEvaluationData:edit'">
          <Icon icon="fluent:add-12-filled" /> {{ t('新增') }}
        </a-button>
      </template>
      <template #firstColumn="{ record }">
        <a @click="handleForm({ dataId: record.dataId })">
          {{ record.evaluationGrade }}
        </a>
      </template>
    </BasicTable>
    <InputForm @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts">
  export default defineComponent({
    name: 'ViewsSportsSportsEvaluationDataList',
  });
</script>
<script lang="ts" setup>
  import { defineComponent } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicTable, BasicColumn, useTable } from '/@/components/Table';
  import { sportsEvaluationDataDelete, sportsEvaluationDataListData } from '/@/api/sports/sportsEvaluationData';
  import { useDrawer } from '/@/components/Drawer';
  import { FormProps } from '/@/components/Form';
  import InputForm from './form.vue';

  const { t } = useI18n('sports.sportsEvaluationData');
  const { showMessage } = useMessage();
  const getTitle = {
    icon: router.currentRoute.value.meta.icon || 'ant-design:book-outlined',
    value: router.currentRoute.value.meta.title || t('测评数据管理管理'),
  };

  const searchForm: FormProps = {
    baseColProps: { lg: 6, md: 8 },
    labelWidth: 90,
    schemas: [
      {
        label: t('学生年级'),
        field: 'evaluationGrade',
        component: 'Select',
        componentProps: {
          dictType: 'vke_grade',
          allowClear: true,
        },
      },
      {
        label: t('学生班级'),
        field: 'evaluationClass',
        component: 'Select',
        componentProps: {
          dictType: 'vke_class',
          allowClear: true,
        },
      },
      {
        label: t('测评学年'),
        field: 'schoolYear',
        component: 'Input',
      },
      {
        label: t('测评学期'),
        field: 'semester',
        component: 'Select',
        componentProps: {
          dictType: 'vke_semester',
          allowClear: true,
        },
      },
      {
        label: t('测评总分'),
        field: 'totalScore',
        component: 'Input',
      },
      {
        label: t('标准分'),
        field: 'standardScore',
        component: 'Input',
      },
      {
        label: t('附加分'),
        field: 'additionalScore',
        component: 'Input',
      },
      {
        label: t('测评总分对应等级'),
        field: 'grade',
        component: 'Select',
        componentProps: {
          dictType: 's_total_grade',
          allowClear: true,
        },
      },
      {
        label: t('测评总结评语'),
        field: 'summary',
        component: 'Input',
      },
      {
        label: t('测评学生基本信息'),
        field: 'studentId',
        component: 'Input',
      },
      {
        label: t('测评负责老师'),
        field: 'teacherId',
        component: 'Input',
      },
      {
        label: t('测评时间'),
        field: 'evaluationTime',
        component: 'DatePicker',
        componentProps: {
          format: 'YYYY-MM-DD HH:mm',
          showTime: { format: 'HH:mm' },
        },
      },
      {
        label: t('测评状态'),
        field: 'evaluationStatus',
        component: 'Input',
      },
    ],
  };

  const tableColumns: BasicColumn[] = [
    {
      title: t('学生年级'),
      dataIndex: 'evaluationGrade',
      key: 'a.evaluation_grade',
      sorter: true,
      width: 230,
      align: 'left',
      dictType: 'vke_grade',
      slots: { customRender: 'firstColumn' },
    },
    {
      title: t('学生班级'),
      dataIndex: 'evaluationClass',
      key: 'a.evaluation_class',
      sorter: true,
      width: 130,
      align: 'center',
      dictType: 'vke_class',
    },
    {
      title: t('测评学年'),
      dataIndex: 'schoolYear',
      key: 'a.school_year',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('测评学期'),
      dataIndex: 'semester',
      key: 'a.semester',
      sorter: true,
      width: 130,
      align: 'center',
      dictType: 'vke_semester',
    },
    {
      title: t('测评总分'),
      dataIndex: 'totalScore',
      key: 'a.total_score',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('标准分'),
      dataIndex: 'standardScore',
      key: 'a.standard_score',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('附加分'),
      dataIndex: 'additionalScore',
      key: 'a.additional_score',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('测评总分对应等级'),
      dataIndex: 'grade',
      key: 'a.grade',
      sorter: true,
      width: 130,
      align: 'center',
      dictType: 's_total_grade',
    },
    {
      title: t('测评总结评语'),
      dataIndex: 'summary',
      key: 'a.summary',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('测评学生基本信息'),
      dataIndex: 'studentId',
      key: 'a.student_id',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('测评负责老师'),
      dataIndex: 'teacherId',
      key: 'a.teacher_id',
      sorter: true,
      width: 130,
      align: 'left',
    },
    {
      title: t('测评时间'),
      dataIndex: 'evaluationTime',
      key: 'a.evaluation_time',
      sorter: true,
      width: 130,
      align: 'center',
    },
    {
      title: t('测评状态'),
      dataIndex: 'evaluationStatus',
      key: 'a.evaluation_status',
      sorter: true,
      width: 130,
      align: 'left',
    },
  ];

  const actionColumn: BasicColumn = {
    width: 160,
    actions: (record: Recordable) => [
      {
        icon: 'clarity:note-edit-line',
        title: t('编辑测评数据管理'),
        onClick: handleForm.bind(this, { dataId: record.dataId }),
        auth: 'sports:sportsEvaluationData:edit',
      },
    ],
  };

  const [registerDrawer, { openDrawer }] = useDrawer();
  const [registerTable, { reload }] = useTable({
    api: sportsEvaluationDataListData,
    beforeFetch: (params) => {
      return params;
    },
    columns: tableColumns,
    actionColumn: actionColumn,
    formConfig: searchForm,
    showTableSetting: true,
    useSearchForm: true,
    canResize: true,
  });

  function handleForm(record: Recordable) {
    openDrawer(true, record);
  }

  async function handleDelete(record: Recordable) {
    const res = await sportsEvaluationDataDelete(record);
    showMessage(res.message);
    handleSuccess();
  }

  function handleSuccess() {
    reload();
  }
</script>
